﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System.Windows.Forms;

namespace Swsk33.SimpleArcEngine.Dialog
{
	public partial class SelectGetSquareDialog : Form
	{
		/// <summary>
		/// 传入地图控件
		/// </summary>
		private AxMapControl mapControl;

		/// <summary>
		/// 传入画的多边形
		/// </summary>
		private IGeometry trackPolygon;

		public SelectGetSquareDialog(AxMapControl mapControl, IGeometry trackPolygon)
		{
			this.mapControl = mapControl;
			this.trackPolygon = trackPolygon;
			InitializeComponent();
		}

		private void ok_Click(object sender, System.EventArgs e)
		{
			Close();
		}

		private void resultList_DoubleClick(object sender, System.EventArgs e)
		{
			IFeatureLayer layer =(FeatureLayer)mapControl.get_Layer(0);
			IQueryFilter filter = new QueryFilter();
			filter.SubFields = "*";
			filter.WhereClause = layer.FeatureClass.OIDFieldName + "=" + resultList.SelectedItems[0].Text;
			IFeatureCursor cursor = layer.Search(filter, false);
			ITopologicalOperator mainOperator = (ITopologicalOperator)trackPolygon;
			IFeature feature = null;
			while((feature = cursor.NextFeature()) != null)
			{
				IGeometry shape = feature.Shape;
				((ITopologicalOperator)shape).Simplify();
				mapControl.FlashShape(mainOperator.Intersect(shape, esriGeometryDimension.esriGeometry2Dimension));
			}
		}
	}
}
